Mersenne Primes

Introduction

Why Mathematicians Care About Special Primes

Defining Mersenne Numbers and Mersenne Primes

Why the Expression \(2^p - 1\) Is So Important

A Historical Glimpse: Marin Mersenne and His List

When Is \(2^p - 1\) Prime?

The Lucas–Lehmer Test (Explained Gently)

The Lucas–Lehmer test is a fast and elegant way to check whether a number of the form $$M_p = 2^p - 1$$ is prime, but only when $p$ itself is prime.

The basic idea

  1. Start with $$s_1 = 4$$
  2. Repeatedly compute $$s_{n+1} = s_n^2 - 2$$ reducing the result modulo $M_p = 2^p - 1$ each time.
  3. After doing this $p - 2$ times, look at the final value:
    • If it is 0, then $M_p$ is prime.
    • Otherwise, $M_p$ is composite.

This test is extremely efficient for large $p$, which is why computers use it to find giant primes.

Example: Testing whether \(2^5 - 1 = 31\) is prime

Here $p = 5$, so we will compute three values:
$s_1$, $s_2$, $s_3$ (because $p - 2 = 3$).

Step 1: Start the sequence

Step 2: Compute \(s_2\)

Step 3: Compute \(s_3\)

Step 4: Compute \(s_4\)

We need one more step because $p - 2 = 3$ means we compute up to $s_4$.

Final check

Additional Example: Showing that $2^{11} - 1$ Is Not Prime

We will test whether $$M_{11} = 2^{11} - 1 = 2047$$ is prime.

Since \(p = 11\), we must compute the Lucas–Lehmer sequence up to \(s_{10}\) (because \(p - 2 = 9\)).

Step 1: Start the sequence

Step 2: Compute $s_2$

Step 3: Compute $s_3$

Step 4: Compute $s_4$

Step 5: Compute $s_5$

Step 6: Compute $s_6$

Step 7: Compute $s_7$

Step 8: Compute $s_8$

Step 9: Compute $s_9$

Step 10: Compute $s_{10}$

Final check

And indeed, $$2047 = 23 \times 89$$ so the Lucas–Lehmer test correctly identifies it as composite.

Examples of Known Mersenne Primes

Some early examples:

Modern examples are enormous—millions of digits long.

How Rare Are They? Patterns, Myths, and Unknowns

Modern Searches and the Role of Supercomputers

Calculator

mersennePrime()

  • Returns a specific Mersenna prime or list of primes.
mersennePrime(1) mersennePrime([1, 2, 3]) mersennePrime(1:10)

mersennePrimeExp()

  • Returns the exponents of all known Mersenne primes, or given an index, will return a specific exponent.
  • Rather than returning the actual primes, this function returns only the exponent, i.e. it returns the value of $p$ in $2^p-1$.
mersennePrimeExp() mersennePrimeExp(1) mersennePrimeExp([1, 2, 3]) mersennePrimeExp(1:10)

lucasLehmer()

  • Performs the Lucas-Lehmer test for a given exponent .
lucasLehmer(7)

lucasLehmerVerbose()

  • Performs the Lucas-Lehmer test for a given exponent .
  • Each step in the process is shown in the output.
lucasLehmerVerbose(7)

Exercises

  1. Compute $2^p - 1$ for $p = 2, 3, 5$, and decide which are prime.

    Solution

    Compute $2^p - 1$ for $p = 2,3,5$ and decide which are prime.

    • For $p = 2$: $$2^2 - 1 = 4 - 1 = 3$$ 3 is prime.
    • For $p = 3$: $$2^3 - 1 = 8 - 1 = 7$$ 7 is prime.
    • For $p = 5$: $$2^5 - 1 = 32 - 1 = 31$$ 31 is prime.
    • Conclusion: All three, $3$, $7$, and $31$, are primes, so they are all Mersenne primes.
  2. Explain why $p$ must be prime for $2^p - 1$ to be prime.

    Solution

    Explain why $p$ must be prime for $2^p - 1$ to be prime.

    • Key idea: If $p$ is not prime, say $p = ab$ with integers $a,b > 1$, then: $$2^p - 1 = 2^{ab} - 1$$
    • This can be factored using a standard algebraic pattern: $$2^{ab} - 1 = (2^a)^b - 1$$ which is divisible by $2^a - 1$.
    • So if $p$ is composite, $2^p - 1$ has a non-trivial factor and cannot be prime.
    • Therefore, for $2^p - 1$ to be prime, $p$ must be prime.
  3. Check whether $2^{11} - 1$ is prime by factoring 2047.

    Solution

    Check whether $2^{11} - 1$ is prime by factoring 2047.

    • First compute: $$2^{11} - 1 = 2048 - 1 = 2047$$
    • Try small prime divisors:
      • Check division by $23$: $$2047 \div 23 = 89$$
      so $$2047 = 23 \times 89$$
    • Since 2047 has factors other than $1$ and itself, it is not prime.
    • So $2^{11} - 1$ is not a Mersenne prime.
  4. Write the binary representation of $2^7 - 1$.

    Solution

    Write the binary representation of $2^7 - 1$.

    • First compute: $$2^7 - 1 = 128 - 1 = 127$$
    • In binary, $2^7$ is written as a 1 followed by seven 0s: $$2^7 = 10000000_2$$
    • Subtracting 1 gives a string of seven 1s: $$2^7 - 1 = 127 = 01111111_2$$
    • Often we drop the leading 0, so we can write: $$127 = 1111111_2$$
  5. List three reasons why Mersenne primes are useful in computer science.

    Solution

    List three reasons why Mersenne primes are useful in computer science.

    Any three of the following (or similar) are acceptable:

    • Efficient arithmetic:
      • Numbers of the form $2^p - 1$ are convenient for computers because they are closely related to powers of 2, which fit naturally with binary hardware.
    • Fast primality testing:
      • The Lucas–Lehmer test works specifically and very efficiently for Mersenne numbers $2^p - 1$, making very large primes practical to find.
    • Use in cryptography / large prime generation:
      • Large Mersenne primes help test methods and hardware for generating big primes, which are important in cryptographic systems.
    • Simple binary structure:
      • A Mersenne number has a binary representation of all 1s, which can simplify certain bitwise operations.
  6. For $p = 5$, run the first two steps of the Lucas–Lehmer sequence:
    • $s_1 = 4$
    • Compute $s_2 = s_1^2 - 2$

    Solution

    For $p = 5$, run the first two steps of the Lucas–Lehmer sequence: $s_1 = 4$, compute $s_2 = s_1^2 - 2$.

    • Given: $$s_1 = 4$$
    • Compute $s_2$: $$s_2 = s_1^2 - 2 = 4^2 - 2 = 16 - 2 = 14$$
    • For the full test, you would then reduce $s_2$ modulo $2^5 - 1 = 31$, but here:
      • $$14 \mod 31 = 14$$
    • Answer: $s_2 = 14$ (and modulo 31 it is still 14).
  7. Research task: Find the current largest known Mersenne prime (just the exponent $p$).

    Solution

    Research task: Find the current largest known Mersenne prime (just the exponent $p$).

    • This value changes over time as new Mersenne primes are discovered.
    • The largest known Mersenne prime at the time of writing, is $2^{136279841} − 1$.
    • It was discovered by the Great Internet Mersenne Prime Search (GIMPS) in October 2024.
    • It has over 41 million digits (41,024,320 digits).
  8. Explain why $2^{23} - 1$ is not prime.

    Solution

    Explain why $2^{23} - 1$ is not prime.

    • First compute: $$2^{23} - 1 = 8\,388\,608 - 1 = 8\,388\,607$$
    • We can show it is not prime by finding a factor. One such factorization is: $$8\,388\,607 = 47 \times 178\,481$$
    • Because it has non-trivial factors (47 and 178481), $2^{23} - 1$ is not prime.
    • Therefore, it is not a Mersenne prime.